package com.znf.base;

import com.znf.base.enums.ResultCodeEnum;
import lombok.Data;

@Data
public class Result<T> {
    private String code;
    private String msg;
    private T data;

    public Result() {
    }

    public Result(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result(ResultCodeEnum resultCodeEnum) {
        this.code = resultCodeEnum.getCode();
        this.msg = resultCodeEnum.getMsg();
    }

    public static Result<Void> success() {
        return new Result<>(ResultCodeEnum.SUCCESS);
    }

    public static <T> Result<T> success(T data) {
        return new Result<T>(ResultCodeEnum.SUCCESS).setData(data);
    }

    public static Result<Void> fail() {
        return new Result<>(ResultCodeEnum.FAIL);
    }

    public static <T> Result<T> fail(T data) {
        return new Result<T>(ResultCodeEnum.FAIL).setData(data);
    }

    public Result<T> setData(T data) {
        this.data = data;
        return this;
    }
}
